//
//  AboutUSViewController.m
//  SP2P
//
//  Created by 吴建东 on 16/6/6.
//  Copyright © 2016年 EIMS. All rights reserved.
//

#import "AboutUSViewController.h"
#import "AboutUSCell.h"
#import "MessageViewController.h"
#import "CompanyIntroductionViewController.h"
#import "WXApi.h"
@interface AboutUSViewController ()<UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate>
{
    NSMutableArray *_titleDataArray;
    NSMutableArray *_imageDataArray;
    NSMutableArray *_detailDataArray;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UILabel *versionLabel;

@end

@implementation AboutUSViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self initNavBarTitle:@"关于我们" andLeftItemName:@"返回" andRightItemName:@""];
    
    [self initData];
    [self initView];
}

#pragma mark - Action
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag == 11) {
        if (buttonIndex == 1) {
            NSString *phoneNum = [CustomerPhone stringByReplacingOccurrencesOfString:@"-" withString:@""];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phoneNum]]];
        }
    }else if (alertView.tag==12 && buttonIndex==0) {
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        pasteboard.string = APPName;
        }

}


#pragma mark - TableView
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:     //官方公告
        {
            MessageViewController *public = [[MessageViewController alloc] init];
            [self.navigationController pushViewController:public animated:YES];
        }
            break;
        case 1:     //官方微信
        {//公众号已复制到剪贴板，您可在微信-通讯录-公众号“+”搜索框粘贴'随取宝'公众号，点击关注即可。
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"" message:[NSString stringWithFormat:@"公众号已复制到剪贴板,你可以微信-通讯录-公众号“+”搜索框粘贴\"%@\"公众号,点击关注即可。",APPName] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
            alertView.tag = 12;
            [alertView show];
        
        }
            break;
        case 2:     //客服电话
        {
            UIAlertView *alertView1 = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"客服热线 %@",@""] message:CustomerPhone delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"拨打", nil];
            alertView1.delegate = self;
            alertView1.tag = 11;
            [alertView1 show];
        }
            break;
        case 3:     //了解我们
        {
            CompanyIntroductionViewController *company = [[CompanyIntroductionViewController alloc] init];
            [self.navigationController pushViewController:company animated:YES];
            
        }
            break;
            
        default:
            break;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _titleDataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"cellID";
    AboutUSCell *cell = [_tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[NSBundle mainBundle] loadNibNamed:@"AboutUSCell" owner:self options:nil][0];
        cell.selectionStyle = UITableViewCellSelectionStyleDefault;
    }
    cell.leftImageView.image = [UIImage imageNamed:_imageDataArray[indexPath.row]];
    cell.titleLabel.text = _titleDataArray[indexPath.row];
    cell.detailLabel.text = _detailDataArray[indexPath.row];
    if (indexPath.row == _detailDataArray.count-1) {
        cell.arrowImageView.hidden = YES;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    cell.frame=CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width, KAdaptNum(44));
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [self tableView:tableView cellForRowAtIndexPath:indexPath].frame.size.height;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView viewWithFrame:RECTMAKE(0, 0, MSWIDTH, 0) backgroundColor:[UIColor whiteColor] superview:nil];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0f;
}


- (void)initData {
    _titleDataArray = [[NSMutableArray alloc] initWithArray:@[@"官方公告",@"关注官方微信",@"拨打客服电话",@"了解我们"]];
    _imageDataArray = [[NSMutableArray alloc] initWithArray:@[@"about_public",@"about_wechat",@"about_phone",@"about_knowus"]];
   
    _detailDataArray = [[NSMutableArray alloc] initWithArray:@[@"",@"随取宝",CustomerPhone,Baseurl]];
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    _versionLabel.text = [NSString stringWithFormat:@"版本号  %@",appCurVersion];
    
    
}

- (void)initView {
    _versionLabel.font = KFontSize(15);
    _tableView.frame = RECTMAKE(0, GetMaxY(_versionLabel)+KAdaptNum(30), self.view.frame.size.width, self.view.frame.size.height);
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.estimatedRowHeight = KAdaptNum(44);
    _tableView.bounces = NO;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
